package xin.nick.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: Nick inickning@outlook.com
 * @Date: 2021/2/27 12:02
 * @Description:
 */
@RestController
public class HelloController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    UserRemoteClient userRemoteClient;

    @HystrixCommand(fallbackMethod = "defaultCallHello",commandProperties = {
            @HystrixProperty(name="execution.isolation.strategy", value = "THREAD")
    }
    )
    @GetMapping("/callHello")
//    @HystrixCommand(fallbackMethod = "defaultCallHello")
    public String callHello() {
        String result = restTemplate.getForObject("http://localhost:8088/house/hello", String.class);
        return result;
    }

    @GetMapping("/callHello2")
    public String callHello2() {
        String result = userRemoteClient.hello();
        return result;
    }

    @GetMapping("/callHello3")
    public String callHello3() {
        String result = "OK";
        return result;
    }

    public String defaultCallHello() {
        return "fail";
    }
}
